﻿//////////////////////////////////////////////////////////////////////////////
//
//  Copyright © 1998-2024 Glodon Company Limited.  All rights reserved.
//
//  Use of this software is subject to the terms of the Glodon license
//  agreement provided at the time of installation or download, or which
//  otherwise accompanies this software in either electronic or hard copy form.  
//
//////////////////////////////////////////////////////////////////////////////


#pragma once
#include "GnufItem.h"
#include "GnufInfo.h"
#include "GnufCheckGroupControl.h"
#include "GnufCheckButton.h"

namespace gnuf {
    class NameValuePair;
    class QtCheckGroup;

    class GNUF_BASE_EXPORT CheckGroup final
        : public ItemWith<QtCheckGroup>
        , public CheckGroupControlAdpatation
    {
        CANNOT_COPY_OR_ASSIGN(CheckGroup);
    public:
        explicit CheckGroup(NameValuePair*);
        virtual ~CheckGroup();
        void AddItem(gcmp::OwnerPtr<Info>& info);
        void InsertItemAt(int index, gcmp::OwnerPtr<Info>& info);
        void DeleteItemAt(int index);
        void ClearItem();

        int GetSelectedIndex() const { return m_currIndex; }
        bool GetCheckStatus(int index) const { return m_checkedStates.at(index); }

        void SetSelectedIndex(int index, bool outside = true);
        void SetCheckStatus(int index, bool checked, bool outside = true);

        bool IsExclusive() { return m_bExclusive; }
        void SetExclusive(bool is) { m_bExclusive = is; }

        void AddButtonItem(gcmp::OwnerPtr<CheckButton>& button) { m_buttons.push_back(std::move(button)); }
        std::vector<gcmp::OwnerPtr<CheckButton>>& GetButtonItems() { return m_buttons; }

        const std::vector<gcmp::OwnerPtr<Info>>& GetItemInfos() const { return m_itemInfos; }
        ECheckGroupStyle GetCheckGroupStyle() const;
        ECheckGroupDirection GetDirection() const;
        static const EItemType Type;

    protected:
        // Inherits from ItemWith...
        virtual void onDisconnectFromMyQtItem() override;
        virtual void onPostAbilityChanged() override;
        virtual void onPostAppearanceSettingChanged() override;

        // Inherits from CheckGroupControlAdpatation...
        virtual void onCurrentIndexChanged(int) override;
        virtual void onCheckStatusChanged(int, bool) override;
        virtual void onAbilityChanged(bool) override;
        virtual void onCollectLocation(std::set<const gcmp::UniqueString *> &) const override;

    private:
        std::vector<gcmp::OwnerPtr<Info>> m_itemInfos;
        std::vector<gcmp::OwnerPtr<CheckButton>> m_buttons;
        int m_currIndex;
        std::map<int,bool> m_checkedStates;
        bool m_bExclusive;
    };
}
